/**
 * Created by zhangligang
 * Email: tzhang2450@163.com
 * Date: 2018/8/14
 * Time: 03:52
 */
$(function(){

    $('.btn-save').on('click', function() {
        var data = {
            name : $('.region-name').val()
        };
        if (checkForm(data)) {
            sendAjax('/v1/manager/save/region', 'post', {data:data}, function(json) {
                var div = '<div><input type="hidden" class="jump-url" value="/manager/apart/region.html">' + json.message + '</div>';
                $('#action-tip .modal-body .tip-content').html(div);
                $('#action-tip').modal('show');
            });
        }
    });

    $('#action-tip').on('hide.bs.modal', function(){
        if ($(this).find('.jump-url').val()) {
            location.href = $(this).find('.jump-url').val();
        }
        $(this).find('.tip-content').text('');
    });
});

function checkForm(data) {
    if (!data.name) {
        $('#action-tip .modal-body .tip-content').text('请填写区域名称');
        $('#action-tip').modal('show');
        return false;
    }
    return true;
}